//
//  CertificateManagerCell.m
//  GasBusiness
//
//  Created by zfc on 2021/8/1.
//

#import "CertificateManagerCell.h"

@interface CertificateManagerCell ()

@property (nonatomic, strong) UIImageView *imgV;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *startTimeLab;
@property (nonatomic, strong) UILabel *endTimeLab;
@property (nonatomic, strong) UILabel *statusLab;

@end

@implementation CertificateManagerCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setUI {

    UIView *backView = [[UIView alloc] init];
    backView.backgroundColor = WhiteColor;
    [self.contentView addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.contentView);
        make.leading.top.equalTo(self.contentView);
    }];

    UIImageView *imgV = [[UIImageView alloc] init];
    imgV.backgroundColor = ColorEE;
    imgV.cornerRadius = 5;
    imgV.clipsToBounds = YES;
    [backView addSubview:imgV];
    [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(backView);
        make.leading.equalTo(backView).offset(15);
        make.top.equalTo(backView).offset(8);
        make.height.width.mas_equalTo(120);
    }];

    UILabel *titleLab = [[UILabel alloc] init];
    titleLab.text = @"";
    titleLab.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
    titleLab.textColor = Color333;
    [backView addSubview:titleLab];
    self.titleLab = titleLab;
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imgV).offset(10);
        make.leading.equalTo(imgV).offset(15);
        make.trailing.equalTo(backView).offset(-15);
    }];

    UILabel *startTimeLab = [[UILabel alloc] init];
    startTimeLab.text = @"";
    startTimeLab.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
    startTimeLab.textColor = Color333;
    [backView addSubview:startTimeLab];
    self.startTimeLab = startTimeLab;
    [startTimeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLab.mas_bottom).offset(20);
        make.leading.equalTo(imgV).offset(15);
        make.trailing.equalTo(backView).offset(-15);
    }];

    UILabel *endTimeLab = [[UILabel alloc] init];
    endTimeLab.text = @"";
    endTimeLab.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
    endTimeLab.textColor = Color333;
    [backView addSubview:endTimeLab];
    self.endTimeLab = endTimeLab;
    [endTimeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(startTimeLab.mas_bottom).offset(10);
        make.leading.equalTo(imgV).offset(15);
        make.trailing.equalTo(backView).offset(-15);
    }];

    UILabel *statusLab = [[UILabel alloc] init];
    statusLab.text = @"";
    statusLab.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
    statusLab.textColor = Color333;
    [backView addSubview:statusLab];
    self.statusLab = statusLab;
    [statusLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(endTimeLab.mas_bottom).offset(10);
        make.leading.equalTo(imgV).offset(15);
        make.trailing.equalTo(backView).offset(-15);
    }];

}

- (void)setDic:(NSDictionary *)dic {
    _dic = dic;

    [self.imgV sd_setImageWithURL:[NSURL URLWithString:dic[@"img"]]];
    self.startTimeLab.text = [NSString stringWithFormat:@"颁发时间：%@", [Untils setTimeWithTime:dic[@"created_at"] format:@"yyyy.MM.dd"]];
    self.endTimeLab.text = [NSString stringWithFormat:@"到期时间：%@", [Untils setTimeWithTime:dic[@"award_time"] format:@"yyyy.MM.dd"]];
    NSInteger status = [dic[@"status"] intValue];
    if (status == 1) {
        self.statusLab.text = [NSString stringWithFormat:@"状态：%@", @"有效"];
    } else {
        self.statusLab.text = [NSString stringWithFormat:@"状态：%@", @"失效"];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
